package com.axjy.web;

import com.axjy.pojo.Admin;
import com.axjy.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by 13802 on 2018/1/25.
 */
@Controller
public class AdminHandler {

    @Resource
    protected AdminService adminService;

    //登录
    @RequestMapping("/login")
    public String login(String username, String password, Model model, HttpSession session){
        Admin admin=adminService.login(username,password);
        if(admin==null){
            model.addAttribute("err","用户名或密码错误！");
            return "forward:/login.jsp";
        }
        session.setAttribute("username",username);
        //重定向到登陆界面
        return "redirect:/index.jsp";
    }

    @RequestMapping("/logout")
    public String logout(HttpSession session)throws Exception{

        //清除session
        session.invalidate();

        //重定向到登陆界面
        return "redirect:login.jsp";
    }
}
